package com.jy.rhin.support.notification.client;

import com.alibaba.fastjson.JSON;
import com.jy.rhin.infra.exception.RhinAggrErrorType;
import com.jy.rhin.infra.exception.RhinAggrException;
import com.jy.rhin.sdk.dto.notification.resp.PublishMessageDto;
import com.jy.rhin.support.feign.NotifyFeign;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.net.URI;

/**
 * @Description: Http调用客户端
 * @Author: lww
 * @Date: 2022/7/29 9:33
 */
@Service("HTTP")
public class NotificationClientHttpImpl implements NotificationClient {

    @Resource
    NotifyFeign notifyFeign;

    @Override
    public void notify(PublishMessageDto publishMessage) {
        URI uri = null;
        try {
            uri = new URI(publishMessage.getAddressUrl());
        } catch (Exception e) {
            throw new RhinAggrException(RhinAggrErrorType.MESSAGE_SEND_URL_ERROR);
        }
        notifyFeign.notify(uri, JSON.parseObject(publishMessage.getMessage()));
    }
}
